package yxy.game.pm2.active.command.signin;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.active.module.ActiveModule_签到;
import yxy.game.pm2.bean.Currency;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ActiveMessage;
import yxy.game.pm2.message.ActiveMessage.ActSigninInfoRequest;

import java.util.ArrayList;

/**
 * 签到信息
 * @author Dell
 *
 */
@MessageType(proto = Command.ActSigninInfo, classtype = ActiveMessage.ActSigninInfoRequest.class)
public class CMD_Active_签到_Info extends Command<ActSigninInfoRequest> {

	@Override
	public void execute(MessageSource messageSource, ActSigninInfoRequest request) throws Exception {
		String pcode = messageSource.getTag();
		
		ActiveMessage.ActSigninInfoResponse.Builder response = ActiveMessage.ActSigninInfoResponse.newBuilder();
		
		ActiveModule_签到 am = ActiveModule_签到.get(pcode,false);
		int login = am.getLoginin();
		
		ArrayList<Currency> curs = am.signininfo();
		for(int i = 0; i < curs.size(); i++) {
			ActiveMessage.SignInInfo.Builder build = ActiveMessage.SignInInfo.newBuilder();
			Currency cur = curs.get(i);
			int num = (int) cur.getNumber();
			
			build.setId(i + 1);
			build.setType(cur.getType().getNumber());
			build.setDataId(cur.getDataId());			
			build.setNumber(num);
			response.addSignins(build);
		}	
		
		ArrayList<Integer> punchins = am.getPunchins();
		ArrayList<Integer> cangets = am.cangetlist();
		

		
		response.setMonthdays(am.getMonthdays());
		response.setHadget(punchins.toString());
		response.setCanget(cangets.toString());
		
		response.setGetpay(login);
		response.setCangetpay(am.candrawpaysignin());
		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, ActiveMessage.ActSigninInfoResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
	
}
